#include<iostream>
#include<iomanip>
using namespace std;
int n;
int arr[100], visited[100];

void dfs(int step)
{
    if (step == n) {
        for (int i = 0; i < n; i++) {
            cout << setw(5) << arr[i];
        }
        cout << endl;
        return;
    }
    for (int i = 1; i <= n; i++) {
        if (visited[i] == 0) {
            visited[i] = 1;
            arr[step] = i;
            dfs(step + 1);
            visited[i] = 0;
        }
    }
}
int main()
{
    while (cin >> n, n) {
        dfs(0);
        cout << endl;
    }
    return 0;
}